import React, { Component } from 'react';
import renovate from '#/utils/renovate';
import emitter from '#/utils/events';

export default class TBasePage extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  _onRenovateClear__() {
    //清除弹出切换菜单提示标识
    renovate.isRenovate = false;
  }

  _onRenovateSet__() {
    //设置弹出切换菜单提示标识
    renovate.isRenovate = true;
  }

  __onListenerUnit__() {
    //添加结算单元修改监听
    this.__eventEmitter__ = this._onChangeUnit.bind(this);
    emitter.addListener('onChangeUnit', this.__eventEmitter__);
  }

  __onListenerRegion__() {
    //添加地域修改监听
    this.__eventRegionEmitter__ = this._onChangeRegion.bind(this);
    emitter.addListener('onChangeRegion', this.__eventRegionEmitter__);
  }

  __onListenerBeforeunload__() {
    //添加浏览器强制刷新监听
    this.__beforeunload = this._onBeforeunload.bind(this);
    window.addEventListener('beforeunload', this.__beforeunload);
  }

  __onListenerMnue__() {
    //添加菜单修改监听
    this.__onMnueChange = this._onMnueChange.bind(this);
    emitter.addListener('onChangeMnue', this.__onMnueChange);
  }

  __onListenerResize__() {
    //添加浏览器大小更改监听
    this.__onWindowResize = this._updatePosition.bind(this);
    window.addEventListener('resize', this.__onWindowResize);
  }

  /**
   * 屏幕修改后监听方法需要在用的类重写
   */
  _updatePosition() {}

  /**
   * 菜单修改后监听方法需要在用的类重写
   */
  _onMnueChange() {}

  /**
   * 结算单元修改后监听方法需要在用的类重写
   */
  _onChangeUnit() {}

  /**
   * 地域修改后监听方法需要在用的类重写
   */
  _onChangeRegion() {}

  /**
   * 浏览器刷新监听方法需要在用的类重写
   */
  _onBeforeunload() {}

  _onGetMenuPermissions(component) {
    const array = this.props.buttonPermissions || [];
    return array.filter((n) => n.component === component).length > 0;
  }

  componentWillUnmount() {
    this.__eventEmitter__ && emitter.removeListener('onChangeUnit', this.__eventEmitter__);
    this.__eventRegionEmitter__ &&
      emitter.removeListener('onChangeRegion', this.__eventRegionEmitter__);
    this.__onMnueChange && emitter.removeListener('onChangeMnue', this.__onMnueChange);
    window.removeEventListener('resize', this.__onWindowResize);
    this.__beforeunload && window.removeEventListener('beforeunload', this.__beforeunload);
  }
  render() {
    return <div />;
  }
}
